import LocalStorage from "../../engine/LocalStorage";
import { Logger } from "../../engine/Logger";

export default class SettingModel {

    public static instance: SettingModel = new SettingModel();

    public static Local_Key: string = "SettingModel";

    public musicVolumn: number = 1; //音乐
    public soundVolum: number = 1; //音效
    public effect: number = 1;
    public vibrate: number = 1;//震动

    public ddz_bg: number = 0;//斗地主背景
    public paodekuai_bg: number = 0; //跑得快背景
    public jianziding_bg: number = 0; //尖子顶背景

    public lastClubNoticeTime:number = 0



    public init() {
        let str: string = LocalStorage.getItem(SettingModel.Local_Key);
        if (str) {
            try {
                let obj: object = JSON.parse(str);
                SettingModel.instance.musicVolumn = obj["musicVolumn"]
                SettingModel.instance.soundVolum = obj["soundVolum"]
                SettingModel.instance.effect = obj["effect"] || 0
                SettingModel.instance.vibrate = obj["vibrate"]
                SettingModel.instance.ddz_bg = obj["ddz_bg"] || 0
                SettingModel.instance.paodekuai_bg = obj["paodekuai_bg"] || 0
                SettingModel.instance.jianziding_bg = obj["jianziding_bg"] || 0
                SettingModel.instance.lastClubNoticeTime = obj["lastClubNoticeTime"] || 0
                Logger.log("SettingModel==", SettingModel.instance)
            } catch (error) {
                SettingModel.instance.saveToLocal();
            }
        }
    }

    public saveToLocal() {
        LocalStorage.setItem(SettingModel.Local_Key, JSON.stringify(SettingModel.instance))
    }
}
